package com.zt.task;

import com.zt.service.AdminCouponsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 优惠券定时任务
 */
@Component
@Slf4j
public class CouponScheduledTask {

    @Autowired
    private AdminCouponsService couponsService;

    /**
     * 每小时执行一次，更新过期优惠券状态
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void updateExpiredCoupons() {
        log.info("开始执行定时任务：更新过期优惠券状态");
        try {
            couponsService.updateExpiredCoupons();
            log.info("定时任务执行完成：更新过期优惠券状态");
        } catch (Exception e) {
            log.error("定时任务执行失败：更新过期优惠券状态", e);
        }
    }
}
